/**
 * Created by SJay on 2018/1/17.
 */
const translatePrice = (price, isDef) => {
  price = price || 0
  var changePrice = price * 100.00
  console.log()
  if (isFinite(changePrice)) {
    // console.log(changePrice.toString().split('.')[1])
    var point = (changePrice.toString().split('.'))[1] || ''
    console.log('point', point.split('')[0] == 4)
    if (point.split('')[0] == 4) {
      changePrice = changePrice + 0.01
    }
  }
  changePrice = Math.round(changePrice) //四舍五入
  changePrice = "00" + changePrice //转化成字符串
  if (isDef) {
    var intNum = changePrice.slice(0, -2)
    var lastNum = changePrice.substr(-2, isDef)
    return [parseInt(intNum), lastNum]
  }
  changePrice = changePrice.split('')
  changePrice.splice(-2, 0, '.')
  changePrice = changePrice.join('')
  changePrice = parseFloat(changePrice).toFixed(2)
  return changePrice
}

export {translatePrice}
